<?php
/**
 * Created by PhpStorm.
 * User: JSQ-SL
 * Date: 2018/11/19
 * Time: 15:37
 */

namespace app\index\table;

use app\index\controller\Login;
use think\Db;
use app\index\service\ExcelService;

class ArchiveFacilityTable extends BaseTable
{
    protected static $table = 'ARCHIVE_FACILITY';
    protected static $view = 'V_ARCHIVE_FACILITY';

    static public function table(){
        return Db::table(static::$view);
    }

    static public function insert($data){
        $yearmonth = $data['ARCHIVE_YEARMONTH'];
        $facilityNo = $data['FACILITY_NO'];
        self::toDate($data,'ENTERTIME');
        self::toDate($data,'OUTFACTORY_DATE');
        self::toDate($data,'INPUTDATE');

        $old = Db::table(static::$table)->where(['ARCHIVE_YEARMONTH'=>$yearmonth,'FACILITY_NO'=>$facilityNo])->find();
        if(empty($old)){
            return Db::table(static::$table)->insert($data);
        }
        else{
            return Db::table(static::$table)
                ->where(['ARCHIVE_YEARMONTH'=>$yearmonth,'FACILITY_NO'=>$facilityNo])
                ->update($data);
        }
    }

}